﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace EventMaker
{
    class Program
    {
        static void Main(string[] args)
        {
            //string xmlFile = "event.xml";
            string xsdFile = AppDomain.CurrentDomain.BaseDirectory + "\\event.xsd";
            string xsdPath = @"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin";


            var myProc = new Process();
            myProc.EnableRaisingEvents = true;
            myProc.ErrorDataReceived += new DataReceivedEventHandler(myProc_ErrorDataReceived);
            myProc.StartInfo.FileName = xsdPath + "\\xsd.exe";
            myProc.StartInfo.WorkingDirectory = xsdPath;
            myProc.StartInfo.Arguments = "/classes /language:C# \"" + xsdFile + "\" /out: \"" + AppDomain.CurrentDomain.BaseDirectory + "\"";
            myProc.Start();
            myProc.WaitForExit();

            //xsd /classes /language:C# PO.xsd


            var reader = new StreamReader("event.cs");
            var str = "";
            string cont = "";
            while ((str = reader.ReadLine()) != null)
            {
                if (str.Contains("public partial class"))
                {
                    var a = str.Split(' ');
                    a[a.Length - 2] = a[a.Length - 2] + ":AbstractEvent";
                    str = String.Join(" ", a);
                }
                cont += str + "\r\n";
            }
            reader.Close();

            var writer = new StreamWriter("event.cs");
            writer.Write(cont);
            writer.Close();
            //public partial class

        }

        static void myProc_ErrorDataReceived(object sender, DataReceivedEventArgs e)
        {
            throw new NotImplementedException();
        }
    }
}
